#include "SqliteHelper.hpp"
#include <cassert>
#include <vector>
// void* arg,       // 用户传进来的指针
// int column_count, // 当前这一行有多少列
// char** column_values, 列值// 当前这一行每一列的值（字符串形式）column_values[1]这样访问
// char** column_names   列名// 每一列的列名，要哪列的，column_names[i]这样访问就行
// 后面三个都是对数据的描述
int SelectCallback(void* arg, int col_count, char** column_values, char** column_names) //每一行数据都会调用这个
{
    std::vector<std::string> *array = static_cast<std::vector<std::string>*>(arg);
    array->push_back(column_values[1]);
    return 0;
}
int main()
{
    SqliteHelper helper("./test.db");
    //1.打开db
    assert(helper.Open());  
    //2.创建table
    const char* ct_sql = "create table if not exists student(sn int primarykey, name varchar(32), age int);";
    helper.Exec(ct_sql);

    //2.1增
    // const char* insert_sql = "insert into student values(1, '张三', 18), (2, '李四',19), (3, '王五', 20);";
    // helper.Exec(insert_sql);
    //2.2删
    // const char* delete_sql = "delete from student where sn=2;";
    // helper.Exec(delete_sql);
    //2.3改
    // const char* update_sql = "update student set name='张小三' where sn = 1;";
    // helper.Exec(update_sql);
    //2.4查
    std::vector<std::string> array;
    const char* select_sql = "select * from student;";
    helper.Exec(select_sql, SelectCallback, &array);
    for(auto &name : array)
        std::cout << name << std::endl;
    //3.关闭
    helper.Close();
    return 0;
}